<%@ Page Language="C#" AutoEventWireup="true" CodeFile="airlines.aspx.cs" Inherits="airlines" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="code"
            DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="code" HeaderText="code" ReadOnly="True" SortExpression="code" />
                <asp:CheckBoxField DataField="low_cost_airline" HeaderText="low_cost_airline" 
                    SortExpression="low_cost_airline" />
            </Columns>
        </asp:GridView>
        <br />
        <br />
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="code" DataSourceID="SqlDataSource1" DefaultMode="Insert">
            <EditItemTemplate>
                code:
                <asp:Label ID="codeLabel1" runat="server" Text='<%# Eval("code") %>'></asp:Label><br />
                low_cost_airline:
                <asp:CheckBox ID="low_cost_airlineCheckBox" runat="server" 
                    Checked='<%# Bind("low_cost_airline") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="Update"></asp:LinkButton>
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel"></asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
                code:
                <asp:TextBox ID="codeTextBox" runat="server" Text='<%# Bind("code") %>'></asp:TextBox><br />
                low_cost_airline:
                <asp:CheckBox ID="low_cost_airlineCheckBox" runat="server" 
                    Checked='<%# Bind("low_cost_airline") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                    Text="Insert"></asp:LinkButton>
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel"></asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                code:
                <asp:Label ID="codeLabel" runat="server" Text='<%# Eval("code") %>'></asp:Label><br />
                low_cost_airline:
                <asp:CheckBox ID="low_cost_airlineCheckBox" runat="server" 
                    Checked='<%# Bind("low_cost_airline") %>' Enabled="false" />
                <br />
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                    Text="Edit"></asp:LinkButton>
                &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                    Text="Delete"></asp:LinkButton>
                &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                    Text="New"></asp:LinkButton>
            </ItemTemplate>
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SparrowDB %>"
            DeleteCommand="DELETE FROM [airlines] WHERE [code] = @code" InsertCommand="INSERT INTO [airlines] ([code], [low_cost_airline]) VALUES (@code, @low_cost_airline)"
            SelectCommand="SELECT * FROM [airlines]" UpdateCommand="UPDATE [airlines] SET [low_cost_airline] = @low_cost_airline WHERE [code] = @code">
            <DeleteParameters>
                <asp:Parameter Name="code" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="low_cost_airline" Type="boolean" />
                <asp:Parameter Name="code" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="code" Type="String" />
                <asp:Parameter Name="low_cost_airline" Type="boolean" />
            </InsertParameters>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
